import 'package:library_8_1/library_8_1.dart';

class Person implements Comparable<Person> {
  final String name;
  final int age;

  Person(this.name, this.age);

  @override
  int compareTo(Person other) {
    if (this.age < other.age) {
      print('return -1 表示当前对象小于比较对象');
      print('$name is younger than ${other.name}.');
      print('  ');
      return -1;
    } else if (this.age == other.age) {
      print('return 0 表示当前对象等于比较对象');
      print('$name is the same age as ${other.name}.');
      print('  ');
      return 0;
    } else {
      print('return 1 表示当前对象大于比较对象');
      print('$name is older than ${other.name}.');
      print('  ');
      return 1;
    }
  }

  @override
  String toString() => '$name: $age';
}

void main() {
  var awesome = Awesome();
  print('awesome: ${awesome.isAwesome}');

  Person alice = Person("Alice", 30);
  Person bob = Person("Bob", 25);
  Person charlie = Person("Charlie", 35);
  Person dogin = Person("Dogin", 30);

  print('人员年龄信息:');
  print(alice);
  print(bob);
  print(charlie);
  print(dogin);
  print('');

  // 比较 Bob 和 Alice
  alice.compareTo(bob);

  // 比较 Charlie 和 Alice
  alice.compareTo(charlie);

  // 比较 Dogin 和 Alice
  alice.compareTo(dogin);
}
